package itcz.example.pattern.behavior_type.command;

import java.util.Map;
import java.util.Set;

/**
 * @ClassName: OrderCommand
 * @Author: ITCZ
 * @Date: 2025-07-23
 * @Description:命令模式-具体命令者角色
 */
public class OrderCommand implements Command {

    // 持有接受者对象
    private SeniorChef receiver;
    // 持有命令对象
    private Order order;

    public OrderCommand(SeniorChef receiver, Order order) {
        this.receiver = receiver;
        this.order = order;
    }

    @Override
    public void execute() {
        System.out.println(order.getDiningTable() + "桌的订单：");
        Map<String, Integer> foodDic = order.getFoodDic();
        Set<String> keys = foodDic.keySet();
        for (String foodName : keys) {
            receiver.makeFood(foodName, foodDic.get(foodName));
        }
        try {
            //停顿一下 模拟做饭的过程
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(order.getDiningTable() + "桌的饭弄好了");
    }
}
